﻿//-----------------------------------------------------------------------
// <copyright file="KeyboardStateProvider.cs" author="Artak Mkrtchyan">
//     Creative Commons - GNU General Public License (http://creativecommons.org/licenses/GPL/2.0/
// </copyright>
// <author>Artak Mkrtchyan</author>
// <email>mkArtak@gmail.com</email>
// <date>24/01/2013</date>
//-----------------------------------------------------------------------

using ConsoleHoster.Common.Utilities;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Input;

namespace ConsoleHoster.Common.UserInput
{
	public class KeyboardStateProvider : IKeyboardStateProvider
	{
		public bool IsKeyDown(Key argKey)
		{
			return Keyboard.IsKeyDown(argKey);
		}

		public bool AnyOfKeysDown(Key argKey1, Key argKey2, params Key[] argAdditionalKeys)
		{
			bool tmpResult = this.IsKeyDown(argKey1) || this.IsKeyDown(argKey2);
			if (!tmpResult && argAdditionalKeys != null)
			{
				tmpResult = argAdditionalKeys.Any(k => this.IsKeyDown(k));
			}

			return tmpResult;
		}

		public bool AllKeysDown(Key argKey1, Key argKey2, params Key[] argAdditionalKeys)
		{
			bool tmpResult = this.IsKeyDown(argKey1) && this.IsKeyDown(argKey2);
			if (argAdditionalKeys != null)
			{
				tmpResult &= this.AllKeysDown(argAdditionalKeys);
			}

			return tmpResult;
		}

		public bool AllKeysDown(IEnumerable<Key> argKeys)
		{
			ValidationManager.RequireArgumentNotNull(argKeys, "argKeys");

			return argKeys.All(k => this.IsKeyDown(k));
		}

		public bool AnyOfKeysDown(IEnumerable<Key> argKeys)
		{
			ValidationManager.RequireArgumentNotNull(argKeys, "argKeys");

			return argKeys.Any(item => this.IsKeyDown(item));
		}
	}
}
